require('dotenv').config();
const { DataSource } = require('typeorm');
const { User } = require('./src/users/users.entity');

const dataSource = new DataSource({
  type: 'sqlite',
  database: 'db.sqlite',
  entities: [User],
  synchronize: false,
  logging: false
});

async function queryUsers() {
  try {
    await dataSource.initialize();
    console.log('数据库连接成功');

    const userRepository = dataSource.getRepository(User);
    const users = await userRepository.find({
      select: ['id', 'phone', 'name']
    });

    console.log('用户列表:');
    console.log(users);

    await dataSource.destroy();
  } catch (error) {
    console.error('查询用户时出错:', error);
  }
}

queryUsers();